﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetMyCircleList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            MyCircleOutParam result = new MyCircleOutParam();
            MyCircleInParam param = new MyCircleInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as MyCircleInParam;

                if (string.IsNullOrEmpty(param.user_id))
                {
                    result.code = "0";
                    result.desc = "用户ID不能为空";

                    isFlag = false;
                }


                if (CommonUtils.IsDisableUsers(param.user_id))
                {
                    result.code = "0";
                    result.desc = "用户状态有问题，请联系管理员";

                    isFlag = false;
                }

                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetMyCircleList(param.user_id);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        MyCircle itemTemp;  

                        foreach(DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new MyCircle();
                            itemTemp.community_id = dr["community_id"].ToString();
                            itemTemp.info = dr["info"].ToString();
                            itemTemp.labels = dr["TagName"].ToString();
                            itemTemp.name = dr["name"].ToString();
                            itemTemp.numbers = dr["numbers"].ToString();
                            itemTemp.circletype = dr["circletype"].ToString();
                            itemTemp.applyNum = dr["applyNum"].ToString();
                            itemTemp.create_userid = dr["create_userid"].ToString();
                            itemTemp.createName = dr["createName"].ToString();
                            result.data.list.Add(itemTemp);
                        }
                    } 
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetMyCircleList", SerializeHelper.JsonSerializer<MyCircleInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<MyCircleInParam, MyCircleOutParam>();
            else
                SafeProcessRequest<MyCircleInParam, MyCircleOutParam>();
        }
    }

    #region 请求参数
    public class MyCircleInParam
    {
        /// <summary>
        /// 必填，	用户ID
        /// </summary>
        public string user_id
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class MyCircleOutParam
    {
        public MyCircleOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new MyCircleList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 用户参与的圈子列表
        /// </summary>
        public MyCircleList data
        { get; set; }
    }

    public class MyCircleList
    {
        public MyCircleList()
        { 
            list = new List<MyCircle>();
        }

        public List<MyCircle> list { get; set; } 
    }
     
    /// <summary>
    /// 用户参与的圈子
    /// </summary>
    public class MyCircle
    { 
        /// <summary>
        ///	圈子ID
        /// </summary>
        public string community_id
        { get; set; } 

        /// <summary>
        ///	圈子名称	
        /// </summary>
        public string name
        { get; set; } 

        /// <summary>
        ///	圈子人数	
        /// </summary>
        public string numbers
        { get; set; } 

        /// <summary>
        ///	所属标签	
        /// </summary>
        public string labels
        { get; set; } 

        /// <summary>
        ///	圈子简介	
        /// </summary>
        public string info
        { get; set; }

        /// <summary>
        ///	圈子类型 0 固定圈子，1 临时圈子,2 我创建的圈子	
        /// </summary>
        public string circletype
        { get; set; }

        /// <summary>
        ///	申请审核人员总数
        /// </summary>
        public string applyNum
        { get; set; }

        /// <summary>
        ///	创建人ID
        /// </summary>
        public string create_userid
        { get; set; }

        /// <summary>
        ///	群主（创建人名）
        /// </summary>
        public string createName
        { get; set; }  
    }
    #endregion 
}